** Command codes to reproduce the results in "Disagreement and Deliberation: Evidence from Three Deliberative Mini-Publics"
** Authors: Kimmo Grönlund, Kaisa Herne, Kim Strandberg and Peter Söderlund
** Dataset: Citizen Deliberation on the Swedish Language and Swedish-speaking Minority in Finland: Post-deliberation Survey 2014
** Source: Full dataset (.csa, .por) available via the Finnish Social Science Data Archive, http://urn.fi/urn:nbn:fi:fsd:T-FSD3102
** Note: The analyses below are based on a reduced version of the dataset available via the Finnish Social Science Data Archive


** Open Nuclear power file
use "...\Swedish data.dta"

** Recode variables

* Recode - Attitudes toward Swedish language (scale 0 to 10)
recode t1_v1 t1_v2 t1_v3 t1_v4 t1_v5 t1_v6 t1_v7 t1_v8 t1_v9 t1_v10 t1_v11 t1_v12 t1_v13 t1_v14 t1_v15 t1_v16 t1_v17 (5=.) (22=.) (33=.) (99=.) (.a=.)
recode t1_v1 t1_v3 t1_v6 t1_v8 t1_v9 t1_v12 t1_v15 t1_v17 (1=10) (2=6.66) (3=3.33) (4=0)
recode t1_v2 t1_v4 t1_v5 t1_v7 t1_v10 t1_v11 t1_v13 t1_v14 t1_v16 (1=0) (2=3.33) (3=6.66) (4=10)

* Identify missing values - Attitudes toward Swedish language (scale 0 to 10)
mvpatterns t1_v1 t1_v2 t1_v3 t1_v4 t1_v5 t1_v6 t1_v7 t1_v8 t1_v9 t1_v10 t1_v11 t1_v12 t1_v13 t1_v14 t1_v15 t1_v16 t1_v17
egen ind_missing = rowmiss(t1_v1 t1_v2 t1_v3 t1_v4 t1_v5 t1_v6 t1_v7 t1_v8 t1_v9 t1_v10 t1_v11 t1_v12 t1_v13 t1_v14 t1_v15 t1_v16 t1_v17)
egen meant1_v1 = mean(t1_v1)
egen meant1_v2 = mean(t1_v2)
egen meant1_v3 = mean(t1_v3)
egen meant1_v4 = mean(t1_v4)
egen meant1_v5 = mean(t1_v5)
egen meant1_v6 = mean(t1_v6)
egen meant1_v7 = mean(t1_v7)
egen meant1_v8 = mean(t1_v8)
egen meant1_v9 = mean(t1_v9)
egen meant1_v10 = mean(t1_v10)
egen meant1_v11 = mean(t1_v11)
egen meant1_v12 = mean(t1_v12)
egen meant1_v13 = mean(t1_v13)
egen meant1_v14 = mean(t1_v14)
egen meant1_v15 = mean(t1_v15)
egen meant1_v16 = mean(t1_v16)
egen meant1_v17 = mean(t1_v17)

* Replace missing values - Attitudes toward Swedish language (scale 0 to 10)
replace t1_v1 = meant1_v1 if t1_v1 == .
replace t1_v2 = meant1_v2 if t1_v2 == .
replace t1_v3 = meant1_v3 if t1_v3 == .
replace t1_v4 = meant1_v4 if t1_v4 == .
replace t1_v5 = meant1_v5 if t1_v5 == .
replace t1_v6 = meant1_v6 if t1_v6 == .
replace t1_v7 = meant1_v7 if t1_v7 == .
replace t1_v8 = meant1_v8 if t1_v8 == .
replace t1_v9 = meant1_v9 if t1_v9 == .
replace t1_v10 = meant1_v10 if t1_v10 == .
replace t1_v11 = meant1_v11 if t1_v11 == .
replace t1_v12 = meant1_v12 if t1_v12 == .
replace t1_v13 = meant1_v13 if t1_v13 == .
replace t1_v14 = meant1_v14 if t1_v14 == .
replace t1_v15 = meant1_v15 if t1_v15 == .
replace t1_v16 = meant1_v16 if t1_v16 == .
replace t1_v17 = meant1_v17 if t1_v17 == .

* Recode - Quality of deliberation
gen agree1 = t3_v38A
gen connected = t3_v38B
gen facts = t3_v38C
gen nontopic = t3_v38D
gen fair = t3_v38E
gen nondominant = t3_v38F
gen agree2 = t3_v38G
gen relations = t3_v38H
gen respect1 = t3_v38I
gen respect2 = t3_v38J
gen personal = t3_v38K
gen active = t3_v38L
gen moredeliberation = t3_v39E
gen participatefuture = t3_v39F
recode agree1 nontopic nondominant agree2 respect1 respect2 (1=4) (2=3) (3=2) (4=1)
recode agree1 connected facts nontopic fair nondominant agree2 relations respect1 respect2 personal active moredeliberation participatefuture (1=0) (2=3.33) (3=6.66) (4=10) (.a=.)

* Identify missing values - Quality of deliberation (scale 0 to 10)
mvpatterns agree1 connected facts nontopic fair nondominant agree2 relations respect1 respect2 personal active moredeliberation participatefuture
egen dep1_missing = rowmiss(relations respect1 respect2 facts connected fair)
egen meanagree1 = mean(agree1)
egen meanconnected = mean(connected)
egen meanfacts = mean(facts)
egen meannontopic = mean(nontopic)
egen meanfair = mean(fair)
egen meannondominant = mean(nondominant)
egen meanagree2 = mean(agree2)
egen meanrelations = mean(relations)
egen meanrespect1 = mean(respect1)
egen meanrespect2 = mean(respect2)
egen meanpersonal = mean(personal)
egen meanactive = mean(active)
egen meanmoredeliberation = mean(moredeliberation)
egen meanparticipatefuture = mean(participatefuture)

* Replace missing values - Quality of deliberation (scale 1 to 10)
egen dep1_rowmean = rmean(agree1 facts relations respect1 respect2)
egen dep2_rowmean = rmean(connected nontopic fair nondominant agree2 active)
egen dep3_rowmean = rmean(moredeliberation participatefuture)
replace agree1 = meanagree1 if agree1 == .
replace facts = meanfacts if facts == .
replace relations = meanrelations if relations == .
replace respect1 = meanrespect1 if respect1 == .
replace respect2 = meanrespect2 if respect2 == .
replace connected = meanconnected if connected == .
replace nontopic = meannontopic if nontopic == .
replace fair = meanfair if fair == .
replace nondominant = meannondominant if nondominant == .
replace agree2 = meanagree2 if agree2 == .
replace active = meanactive if active == .
replace moredeliberation = meanmoredeliberation if moredeliberation == .
replace participatefuture = meanparticipatefuture if participatefuture == .

** Factor analysis

* Factor analysis - Attitudes toward Swedish language (scale 0 to 10)
summ t1_v1 t1_v2 t1_v3 t1_v4 t1_v5 t1_v6 t1_v7 t1_v8 t1_v9 t1_v10 t1_v11 t1_v12 t1_v13 t1_v14 t1_v15 t1_v16 t1_v17
polychoric t1_v1 t1_v2 t1_v3 t1_v5 t1_v6 t1_v7 t1_v8 t1_v9 t1_v11 t1_v13 t1_v14 t1_v15 t1_v16 t1_v17
display r(sum_w)
global N = r(sum_w)
matrix r = r(R)
factormat r, n($N) factors(1) pcf

* Factor analysis - Quality of deliberation index (scale 0 to 10)
summ relations respect1 respect2 facts connected fair
polychoric relations respect1 respect2 facts connected fair
display r(sum_w)
global N = r(sum_w)
matrix r = r(R)
factormat r, n($N) factors(1) pcf

** Generate means and standard deviations

* Generate mean - Attitudes toward Swedish language (scale 1 to 10)
generate swedish_mean = (t1_v1 + t1_v2 + t1_v3 + t1_v5 + t1_v6 + t1_v7 + t1_v8 + t1_v9 + t1_v11 + t1_v13 + t1_v14 + t1_v15 + t1_v16 + t1_v17) / 14

* Generate mean - Quality of deliberation (scale 0 to 10)
generate index_mean = (relations + respect1 + respect2 + facts + connected + fair) / 6

* Standard deviation by group - Attitudes toward Swedish language (scale 1 to 10)
bys group: asrol swedish_mean, stat(sd) xf(focal)
rename sd_swedish_mean tabledisagreement
summ tabledisagreement
generate tabledisagreement_c = tabledisagreement - 1
generate tabledisagreement_c_squared = tabledisagreement_c * tabledisagreement_c

* Group mean centering - Attitudes toward Swedish language (scale 1 to 10)
bys group: asrol swedish_mean, stat(mean) xf(focal)
generate dswedish_mean = swedish_mean - mean_swedish_mean
generate dswedish_mean_abs = abs(dswedish_mean)
summ dswedish_mean_abs
generate dswedish_mean_abs_c = dswedish_mean_abs - 1

** Empirical analyses

* Table 3 - Swedish language - Descriptive statistics
preserve
collapse (mean) sdtabledisagreement=tabledisagreement (mean) meanswedish_mean=swedish_mean, by(group)
sort sdtabledisagreement
tab sdtabledisagreement
sort meanswedish_mean
tab meanswedish_mean
restore

* Table 4 - Swedish language - Mean and standard deviation - Attitudes toward Swedish language (scale 1 to 10)
tabstat index_mean, statistics(mean sd)

* Table 4 - Swedish language - Cronbach's alpha - Quality of deliberation index (scale 0 to 10)
alpha relations respect1 respect2 facts connected fair

* Table 7 - Linear model - Adjusted R2 - OLS regressions without cluser-robust standard errors
regress index_mean c.tabledisagreement_c c.dswedish_mean_abs_c i.enclave i.rules, 

* Table 7 - Curvilinear model - Adjusted R2 - OLS regressions without cluser-robust standard errors
regress index_mean c.tabledisagreement_c##c.tabledisagreement_c c.dswedish_mean_abs_c##c.dswedish_mean_abs_c i.enclave i.rules, 

* Table 7 - Linear model - Coefficients - OLS regression with cluser-robust standard errors
regress index_mean c.tabledisagreement_c c.dswedish_mean_abs_c i.enclave i.rules, vce(cluster group)

* Table 7 - Curvilinear model - Coefficients - OLS regression with cluser-robust standard errors
regress index_mean c.tabledisagreement_c##c.tabledisagreement_c c.dswedish_mean_abs_c##c.dswedish_mean_abs_c i.enclave i.rules, vce(cluster group)

* Figure 5
regress index_mean c.tabledisagreement_c##c.tabledisagreement_c c.dswedish_mean_abs_c##c.dswedish_mean_abs_c i.enclave i.rules, vce(cluster group)
margins, at(tabledisagreement_c=(-0.8(0.01)2.23)) coeflegend post
lincom (_b[1._at] - _b[258._at])
marginsplot, legend(title("", color(black) size(medium))) recast(line) recastci(rarea) plot1opts(lpattern(solid) lcolor(midblue%100) lwidth(thick)) ci1opts(lpattern(solid) color(midblue%30) lcolor(midblue%5) lwidth(thin)) ylabel(5(1)10, angle(90) nogrid glcolor(gs14) labsize(4) format(%9.0f)) ytitle("Process Satisfaction Index", size(5) height(6)) yscale(noline) xscale(noline) xlabel(-1 "0" 0 "1" 1 "2" 2 "3" 3 "4" 4 "5", labsize(4) format(%3.1f)) xtitle("Group-level Disagreement", size(5) height(6)) graphregion(fcolor(white) lcolor(white) lwidth(thick)) plotregion(fcolor(white) lcolor(black) lwidth(thin)) title("") subtitle("Deliberation on Swedish Language", size(5) color(black)) xsize(8) ysize(8) 

* Figure 6
regress index_mean c.tabledisagreement_c##c.tabledisagreement_c c.dswedish_mean_abs_c##c.dswedish_mean_abs_c i.enclave i.rules, vce(cluster group)
margins, at(dswedish_mean_abs_c=(-1(0.01)5)) coeflegend post
lincom (_b[1._at] - _b[60._at])
marginsplot, legend(title("", color(black) size(medium))) recast(line) recastci(rarea) plot1opts(lpattern(solid) lcolor(midblue%100) lwidth(thick)) ci1opts(lpattern(solid) color(midblue%30) lcolor(midblue%5) lwidth(thin)) ylabel(5(1)10, angle(90) nogrid glcolor(gs14) labsize(4) format(%9.0f)) ytitle("Process Satisfaction Index", size(5) height(6)) yscale(noline) xscale(noline) xlabel(-1 "0" 0 "1" 1 "2" 2 "3" 3 "4" 4 "5" 5 "6", labsize(4) format(%3.0f)) xtitle("Individual-level Disagreement", size(5) height(6)) graphregion(fcolor(white) lcolor(white) lwidth(thick)) plotregion(fcolor(white) lcolor(black) lwidth(thin)) title("") subtitle("Deliberation on Swedish Language", size(5) color(black)) xsize(8) ysize(8) 

* Power analysis
power oneslope 0 -0.65, sdx(0.52) sdy(1.14) power(.8)
power oneslope 0 -0.65, sdx(0.52) sdy(1.14) power(.9)
power oneslope 0, n(178) sdx(0.52) sdy(1.14) power(.8)
power oneslope 0, n(178) sdx(0.52) sdy(1.14) power(.9)

